package com.erp.controller;

import com.erp.mapper.FunctionMapper;
import com.erp.mapper.LogMapper;
import com.erp.mapper.vo.FunContent;
import com.erp.pojo.Log;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@RestController
public class FunctionController {

    @Autowired
    private FunctionMapper mapper;
    @Autowired
    private LogMapper logMapper;
    //@LoginRequired
    @RequestMapping("/startFunction")
    public List startFunction(HttpServletRequest request){
        List<Integer> fIdList = new ArrayList<Integer>();
        List<FunContent> funContents=null;
        try {
            String fidStr= (String) request.getSession().getAttribute("fId");

            String[] arr=fidStr.split("/");
            for (int i=0;i<arr.length;i++){
                int id= Integer.parseInt(arr[i]);
                fIdList.add(id);
            }
            funContents = mapper.selectFunContentByFid(fIdList);
            //List<String>list=new ArrayList<String>();
            //for (FunContent content : funContents) {
            //    if (content.getfName().equals("仓库设置")){
            //        System.out.println(1);
            //    }
            //}
        }catch (NullPointerException e){
            System.out.println("功能id截取错误");
            logMapper.insert(new Log(0,e.getMessage(),1,new Date(),Integer.parseInt(String.valueOf(request.getSession().getAttribute("id")))));
        }
        return funContents;
    }



}
